<?php
/**
 * @package Users
 */

 class users extends db
 {
 	function __on_search($user_id,$last_sync_time=0)
 	{
 		global $GO_MODULES, $GO_LANGUAGE, $GO_USERS;

 		//require($GO_LANGUAGE->get_language_file('addressbook'));

 		$sql = "SELECT DISTINCT users.*  FROM users  INNER JOIN acl ON users.acl_id = acl.acl_id ".
 		"LEFT JOIN users_groups ON acl.group_id = users_groups.group_id WHERE (acl.user_id=$user_id ".
 		"OR users_groups.user_id=$user_id) AND mtime>$last_sync_time";

 		$this->query($sql);
 		
 		$search = new search();

 		$db = new db();
 		while($this->next_record())
 		{
 			$cache['table']='users';
 			$cache['id']=$this->f('id');
 			$cache['user_id']=$user_id;
 			$cache['name'] = addslashes(format_name($this->f('last_name'),$this->f('first_name'),$this->f('middle_name')));
 			$cache['link_id'] = $this->f('link_id');
 			$cache['link_type']=8;
 			$cache['description']='';
 			$cache['url']=$GO_MODULES->modules['users']['url'].'user.php?user_id='.$this->f('id');
 			$cache['type']=$GLOBALS['strUser'];
 			$cache['keywords']=addslashes(record_to_keywords($this->Record)).','.$cache['type'];
 			$cache['mtime']=$this->f('mtime');
 				
 			if($search->get_search_result($user_id, $this->f('link_id')))
 			{
 				$db->update_row('se_cache',array('user_id','link_id'), $cache);
 			}else {
 				$db->insert_row('se_cache',$cache);
 			}
 		}
 	}
 }